package com.lft.freshordering.service.impl;

import com.lft.freshordering.entity.Goods;
import com.lft.freshordering.entity.Stypes;
import com.lft.freshordering.mapper.StypesMapper;
import com.lft.freshordering.service.IStypesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tyhxzy
 * @since 2024-12-02
 */
//我的代码
@Service
public class StypesServiceImpl implements IStypesService {

    @Autowired
    private StypesMapper stypesMapper;
    @Override
    public List<Stypes> selectAll() {
        return stypesMapper.selectAll();
    }

    @Override
    public List<Goods> selectByType(Integer id) {
        return stypesMapper.selectByType(id);
    }

    @Override
    public Goods selectByName(String name) {
        return stypesMapper.selectByName(name);
    }

    @Override
    public List<Goods> sou(String goodsName) {
//        String goodsNamee = "%" +goodsName+"%";
        return stypesMapper.sou(goodsName);
    }


    @Override
    public List<Goods> selectAllGoods() {
        return stypesMapper.selectAllGoods();
    }







    @Override
    public List<Stypes> selectList() {
        List<Stypes> stypes = stypesMapper.selectStypes();
        return stypes;
    }

//    @Override
//    public int updatestypes(Stypes stypes) {
//        int updatestypes = stypesMapper.updatestypes(stypes);
//        return updatestypes;
//    }

    @Override
    public int deletestypes(Integer id) {
        int deletestypes = stypesMapper.deletestypes(id);
        return deletestypes;
    }
    public List<Stypes> selectstypess () {

        List<Stypes> sss = new ArrayList<>();


        List<Stypes> stypes = stypesMapper.selectStypess();
        for (Stypes stypes1 : stypes) {
            Stypes ss = new Stypes();
            List<Goods> goods = stypesMapper.selectGoodsByCategoryId(stypes1.getId());
            ss.setId(stypes1.getId());
            ss.setTname(stypes1.getTname());
            ss.setGoods(goods);

            sss.add(ss);
        }
        return sss;
    }
    @Override
    public int updatestypes(Stypes stypes) {
        Integer id2 = stypesMapper.selectss(stypes.getNum2());
        int updatestypes = stypesMapper.updatestypes(stypes.getId(), stypes.getNum2(), stypes.getTname());
        int i1 = stypesMapper.updatestypes2(id2, stypes.getNum());
        Integer i = i1 + updatestypes;
        return i;
    }

    @Override
    public int insertstypes(String tname) {
        Integer i = stypesMapper.selectMaxNum();
        Stypes ss = new Stypes();
        ss.setTname(tname);
        ss.setNum(i + 1);
        System.out.println(ss);
        int inserttname = stypesMapper.inserttname(ss);
        return inserttname;
    }

    @Override
    public List<Goods> selectGoodsByCategoryId(Integer id) {
        List<Goods> goods = stypesMapper.selectGoodsByCategoryId(id);
        return goods;
    }
}
